package model;

import implementor.CategoryMasterImplementor;
import implementor.MaterialMasterImplementor;
import implementor.MaterialSpecificationImplementor;
import dao.CategoryMasterDao;
import dao.MaterialMasterDao;
import dao.MaterialSpecificationDao;
import dto.MaterialMaster;
import dto.MaterialSpecification;

public class Material 
{
	private MaterialMaster materialMasterObject;
	private MaterialSpecification[] spec;
	private MaterialSpecification currentSpecs;
	
	public Material() 
	{
		
	}
	public Material(String mCode,int specCode)
	{
		MaterialMasterDao imp=new MaterialMasterImplementor();
		MaterialSpecificationDao specDao=new MaterialSpecificationImplementor();
		try {
			 materialMasterObject=imp.retreive("mCode", mCode);
			currentSpecs=specDao.retreive("autoSpecCode", specCode+"");	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public Material(String mcode) throws Exception
	{
		MaterialMasterDao mdao=new MaterialMasterImplementor();
		this.materialMasterObject=mdao.retreive("mCode",mcode);
		MaterialSpecificationDao sDao=new MaterialSpecificationImplementor();
		spec=sDao.retreiveArray("mCode", mcode);
	}
	
	
	public Material(MaterialMaster material, MaterialSpecification[] spec) 
	{
		super();
		this.materialMasterObject = material;
		this.spec = spec;
	}
	
	//******************************************************************************
	
	public int getMasterStatus()
	{
		return materialMasterObject.getStatus();
	}
	
	
	public String getMname()
	{
		return materialMasterObject.getmName();
	}
	
	
	public String getMCode()
	{
		return materialMasterObject.getmCode();
	}
	public String getCatCode()
	{
		return materialMasterObject.getCatCode();
	}
	
	public String getCatName()
	{
		CategoryMasterDao catDao=new CategoryMasterImplementor();
		CategoryMaster c=null;
		try {
			 c=catDao.retreive("catCode", materialMasterObject.getCatCode());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return c.getCatName();
	}
	
	public String getUnit()
	{
		return materialMasterObject.getmUnit();
	}

	public void setMaterial(MaterialMaster materialMasterObject) {
		this.materialMasterObject = materialMasterObject;
	}

	public void setSpec(MaterialSpecification[] spec) {
		this.spec = spec;
	}
	public MaterialSpecification getCurrentSpecs() {
		return currentSpecs;
	}
	public void setCurrentSpecs(MaterialSpecification currentSpecs) {
		this.currentSpecs = currentSpecs;
	}
	public MaterialMaster getMaterialMasterObject() {
		return materialMasterObject;
	}
	public void setMaterialMasterObject(MaterialMaster materialMasterObject) {
		this.materialMasterObject = materialMasterObject;
	}
	public MaterialSpecification[] getSpec() {
		return spec;
	}
	

}
